package com.luo.demo;

/**
 * @author: luosiyu
 * @Description:
 * @Version: 1.0
 */

public class Triangle extends shape{
    public Triangle() {
    }

    public Triangle(double a, double b, double c) {
        super(a, b, c);
    }

   private boolean getTriangleArea(){
       if (getA() + getB() > getC() && getB() + getC() > getA() && getC() + getA() > getB()) {
           return true;
       }else {
//           System.out.println("不构成三角形");
           return false;
       }
    }
    @Override
    public double area(){
        double p = (getA()+getB()+getC())/2;
        double a = Math.sqrt(p*(p-getA())*(p-getB())*(p-getC()));
        return Double.valueOf(String.format("%.2f",a)) ;
    }
    @Override
    public double length(){
        return getTriangleArea()? getA()+getB()+getC():0.0;
    }

    @Override
    public String toString() {
        return getTriangleArea()?"三角形的面积="+area()+";周长="+length():"不构成三角形";
    }
}
